// -*- c++ -*-
/*=============================================================================
FILE: CGraphicFont.h

Graphic Font.
=============================================================================*/
#ifndef __CGRAPHICFONT_H__
#define __CGRAPHICFONT_H__

#include "stdTypes.h"
#include "image.h"
#include "rect.h"

enum eFontTextTokenType
{
	FONT_TEXT_TOKEN_NONE     = 0,
	FONT_TEXT_TOKEN_NULL,
	FONT_TEXT_TOKEN_SPACE,
	FONT_TEXT_TOKEN_TAB,
	FONT_TEXT_TOKEN_NEWLINE
};

enum eFontTextFormat
{
	FONT_TEXT_FORMAT_NONE    = 0,
	FONT_TEXT_FORMAT_UNDERLINE,
	FONT_TEXT_FORMAT_REVERSE
};

enum eFontRenderFlags
{
	FONT_RENDER_NONE         = 0x00,
	FONT_RENDER_TRANSPARENT  = 0x01,
	FONT_RENDER_LEFT         = 0x02,
	FONT_RENDER_CENTER       = 0x04,
	FONT_RENDER_RIGHT        = 0x08,
	FONT_RENDER_TOP          = 0x10, 
	FONT_RENDER_MIDDLE       = 0x20,
	FONT_RENDER_BOTTOM       = 0x40
};

typedef struct 
{
	int8                     m_versionGeneration;     // starts at 0x00
	int8                     m_versionMajor;	      // starts at 0x01
	int8                     m_versionMinor;          // starts at 0x01
	int8                     m_flags;                 // lowest order bit is true iff big endian

	int8                     m_ascent;                // baseline position from top
	int8                     m_height;                // font height
	int8                     m_minCharSpacing;        // minimum spacing between character (pixels)
	int8                     m_minLineSpacing;        // minimum spacing between lines (pixels)

	int16                    m_numChars;              // number of graphic characters
	int16                    m_numControlChars;       // number of control characters
} tGTFHeader;

typedef struct
{
	int16                    m_charCode;              // character value
	int16                    m_imageOffsetX;          // x offset in image (pixels)
	int16                    m_imageOffsetY;          // y offset in image (pixels)
	int8                     m_drawWidth;             // width to draw (pixels)
	int8                     m_drawHeight;            // height to draw (pixels)
	int8                     m_drawOffsetX;           // horizontal position adjustment (pixels) - add when drawing
	int8                     m_drawOffsetY;           // vertical position adjustment (pixels) - add when drawing
	int8                     m_width;                 // actual character width (pixels)
	int8                     m_reserved;              // reserved
} tGTFChar;

typedef struct
{
	int16                    m_charCode;              // character value
	int8                     m_reserved;              // reserved
	int8                     m_width;                 // actual character width (pixels)
} tGTFControlChar;

class CGraphicFont
{
public:
	CGraphicFont();
	virtual                  ~CGraphicFont();

	void                     SetFontImage( const char * path );
	void                     SetFontMetrics( const char * path );

	int                      GetFontHeight() const;
	int                      GetMinLineSpacing() const;
	int		                 MeasureTextWidth( const AECHAR *pwszText, int numChars = -1, int maxWidth = -1, int *pCharsFit = NULL ) const;
	void			         DrawString( const AECHAR *pwszText, int x, int y, int flags = FONT_RENDER_NONE) const;
	void			         PaintText( const AECHAR *pwszText, int x, int y, int w, int h, int lineH, int flags = FONT_RENDER_NONE, boolean bIsCentreY = FALSE) const;
	void			         PaintText( const AECHAR *pwszText, int x, int y, int w, int h, int lineH, int maxLines, int startLine, int flags, boolean bIsCentreY) const;
	void                     PaintText( const AECHAR *pwszText, int numChars, const _Rect &clip, int x, int y, float scale, int flags ) const;
	void                     PaintTextAlpha( const AECHAR *pwszText, int numChars, const _Rect &clip, int x, int y, float scale, int flags, uint32 alpha ) const;
	int                      GetWidth( AECHAR c ) const;
protected:
	const tGTFChar *         GetChar( AECHAR c ) const;
	const tGTFControlChar *  GetControlChar( AECHAR c ) const;

	CImage *                 m_pImage;
	uint8 *                  m_pFontMetricsData;
	const tGTFHeader *       m_pHeaderData;
	const tGTFChar *         m_pCharData;
	const tGTFControlChar *  m_pControlCharData;
};


#endif	// #ifndef __CGRAPHICFONT_H__
